package com.huawei.appmarket.service.videostream.viewmodel;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.lifecycle.OnLifecycleEvent;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseCardBean;
import com.huawei.appmarket.service.store.awk.bean.VideoStreamListCardBean;
import com.huawei.appmarket.support.video.VideoPlayer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import o.clm;
import o.dgm;
import o.ContentManager;
import o.emo.c;
import o.emp;
import o.ems;
import o.emt;
import o.emv;
import o.CollectCheck;
import o.evm;
import o.evn;
import o.VideoNetChangeDialog;
import o.VideoNetChangeDialog.d;
import o.evw;
import o.ewm.j;
import o.kp.e;
import o.kt;
import o.la;
import o.lc;

public class VideoStreamViewModel extends lc implements kt, emv {
    private la<Boolean> ʻ = new la();
    private int ʻॱ;
    private List<VideoStreamListCardBean> ʼ = new ArrayList();
    private List<VideoStreamListCardBean> ʽ = new ArrayList();
    private la<List<VideoStreamListCardBean>> ˊ = new la();
    private int ˊॱ = -1;
    private la<Integer> ˋ = new la();
    private evn ˋॱ;
    private emp ˎ = emp.ˎ();
    private la<Boolean> ˏ = new la();
    private boolean ˏॱ;
    private boolean ͺ = false;
    private la<Boolean> ॱ = new la();
    private long ॱˊ = 0;
    private la<Boolean> ॱॱ = new la();
    private ems ᐝ = new ems();

    public la<List<VideoStreamListCardBean>> ˊ() {
        return this.ˊ;
    }

    public la<Boolean> ˎ() {
        return this.ˏ;
    }

    public la<Integer> ˋ() {
        return this.ˋ;
    }

    public la<Boolean> ᐝ() {
        return this.ॱ;
    }

    public la<Boolean> ʽ() {
        return this.ॱॱ;
    }

    public la<Boolean> ॱॱ() {
        return this.ʻ;
    }

    public void ˊ(String str, String str2, long j, int i, int i2) {
        if (this.ˊॱ < 0) {
            this.ˊॱ = i2;
        }
        clm o_clm = new clm();
        o_clm.ˎ(str);
        o_clm.ˋ(this.ˊॱ);
        o_clm.ॱ(String.valueOf(j));
        o_clm.ˊ(str2);
        o_clm.ˏ(12);
        o_clm.setServiceType_(i);
        this.ˏ.ॱ(Boolean.valueOf(true));
        this.ˎ.ˎ(o_clm, new c(this) {
            final /* synthetic */ VideoStreamViewModel ॱ;

            {
                this.ॱ = r1;
            }

            public void ॱ(@NonNull List<VideoStreamListCardBean> list, boolean z, int i) {
                this.ॱ.ˊॱ = i;
                if (CollectCheck.isEmpty(this.ॱ.ʽ) && this.ॱ.ˊ.ˊ() != null) {
                    this.ॱ.ʽ.addAll((Collection) this.ॱ.ˊ.ˊ());
                }
                for (int i2 = 0; i2 < list.size(); i2++) {
                    VideoStreamListCardBean videoStreamListCardBean = (VideoStreamListCardBean) list.get(i2);
                    if (!this.ॱ.ʽ.contains(videoStreamListCardBean)) {
                        this.ॱ.ʽ.add(videoStreamListCardBean);
                    }
                }
                this.ॱ.ˊ.ॱ(this.ॱ.ʽ);
                this.ॱ.ˏ.ॱ(Boolean.valueOf(false));
                this.ॱ.ॱॱ.ॱ(Boolean.valueOf(z));
            }

            public void ˊ(boolean z) {
                this.ॱ.ˏ.ॱ(Boolean.valueOf(false));
                this.ॱ.ॱॱ.ॱ(Boolean.valueOf(z));
            }
        });
    }

    public void ॱ(long j) {
        this.ॱˊ = j;
    }

    public void ˎ(boolean z) {
        this.ˏॱ = z;
    }

    @OnLifecycleEvent(e.ON_RESUME)
    public void onResume() {
        if (this.ˋॱ != null && this.ˋॱ.ˋᐝ() != null && this.ͺ) {
            Context context = this.ˋॱ.ˋᐝ().getContext();
            if (VideoNetChangeDialog.ˊ() && VideoNetChangeDialog.ˏ(context)) {
                VideoNetChangeDialog o_evs = new VideoNetChangeDialog(context);
                o_evs.ˋ(new d(this) {
                    final /* synthetic */ VideoStreamViewModel ˎ;

                    {
                        this.ˎ = r1;
                    }

                    public void ˊ() {
                        if (this.ˎ.ˋॱ != null) {
                            this.ˎ.ˋॱ.ʻ();
                            this.ˎ.ॱˊ();
                        }
                        this.ˎ.ʻ.ॱ(Boolean.valueOf(false));
                    }

                    public void ॱ() {
                        this.ˎ.ʻ.ॱ(Boolean.valueOf(true));
                    }
                });
                o_evs.ˋ();
                return;
            }
            this.ˋॱ.ʻ();
            ॱˊ();
        }
    }

    @OnLifecycleEvent(e.ON_DESTROY)
    public void onDestroy() {
        ʼ();
        this.ʽ.clear();
    }

    @OnLifecycleEvent(e.ON_PAUSE)
    public void onPauseVideo() {
        if (this.ˋॱ == null) {
            return;
        }
        if (this.ˋॱ.ᐝॱ()) {
            this.ͺ = false;
            return;
        }
        this.ˋॱ.ॱˊ();
        this.ͺ = true;
    }

    private void ʼ() {
        if (this.ˋॱ != null) {
            this.ˋॱ.setVideoPlayCallback(null);
            this.ˋॱ.ˍ();
            this.ˋॱ = null;
        }
    }

    private void ˋ(evn o_evn) {
        if (this.ˋॱ != o_evn) {
            ʼ();
            this.ˋॱ = o_evn;
        }
    }

    public void ʻ() {
        if (this.ˋॱ != null) {
            this.ˋॱ.ʼ();
        }
        Context ˋ = ContentManager.getInstant().getContext();
        if (!VideoNetChangeDialog.ˊ() || VideoNetChangeDialog.ˎ(ˋ)) {
            ॱˊ();
        }
    }

    public void ˊ(int i, View view) {
        this.ʻॱ = i;
        ˊ(view);
        if (emt.ॱ()) {
            ॱ(view);
        }
    }

    public void ˊ(int i) {
        if (i == this.ʻॱ) {
            ʼ();
        }
    }

    public void ˏ(int i, View view) {
        if (i != this.ʻॱ) {
            this.ʻॱ = i;
            ˊ(view);
            ॱ(view);
        }
    }

    private void ˊ(View view) {
        if (view != null) {
            evn o_evn = (VideoPlayer) view.findViewById(j.ˊʳ);
            if (o_evn != null) {
                o_evn.setLooping(true);
                o_evn.setCurrentMode(11);
                ˋ(o_evn);
            }
            if (CollectCheck.isEmpty(this.ʽ) && this.ˊ.ˊ() != null) {
                this.ʽ.addAll((Collection) this.ˊ.ˊ());
            }
            if (this.ॱˊ > 0 && this.ˏॱ) {
                int size;
                this.ʼ.clear();
                if (this.ʽ.size() > 12) {
                    size = this.ʽ.size();
                    if (this.ʻॱ > 7 && size - this.ʻॱ > 3) {
                        this.ʼ.addAll(this.ʽ.subList(this.ʻॱ - 8, this.ʻॱ + 4));
                        size = 8;
                    } else if (this.ʻॱ <= 7) {
                        this.ʼ.addAll(this.ʽ.subList(0, 12));
                        size = this.ʻॱ;
                    } else if (size - this.ʻॱ <= 3) {
                        this.ʼ.addAll(this.ʽ.subList(size - 12, size));
                        size = (this.ʻॱ + 12) - size;
                    } else {
                        size = 0;
                    }
                } else {
                    this.ʼ.addAll(this.ʽ);
                    size = this.ʻॱ;
                }
                emp.ˎ().ˊ.put(Long.valueOf(this.ॱˊ), this.ʼ);
                emp.ˎ().ˋ.put(Long.valueOf(this.ॱˊ), Integer.valueOf(size));
            }
        }
    }

    private void ॱ(final View view) {
        if (view != null) {
            if (VideoNetChangeDialog.ˊ() && VideoNetChangeDialog.ˏ(view.getContext())) {
                VideoNetChangeDialog o_evs = new VideoNetChangeDialog(view.getContext());
                o_evs.ˋ(new d(this) {
                    final /* synthetic */ VideoStreamViewModel ˊ;

                    public void ˊ() {
                        this.ˊ.ˎ(view);
                        this.ˊ.ʻ.ॱ(Boolean.valueOf(false));
                    }

                    public void ॱ() {
                        this.ˊ.ʻ.ॱ(Boolean.valueOf(true));
                    }
                });
                o_evs.ˋ();
                return;
            }
            ˎ(view);
        }
    }

    private void ˎ(View view) {
        if (view != null && this.ˋॱ != null) {
            ॱˊ();
            this.ˋॱ.setLooping(true);
            this.ˋॱ.setCurrentMode(11);
            this.ˋॱ.setVideoPlayCallback(new evw(this) {
                final /* synthetic */ VideoStreamViewModel ˎ;

                {
                    this.ˎ = r1;
                }

                public void ॱ(boolean z, int i) {
                    if (i == 1) {
                        if (this.ˎ.ʻॱ < this.ˎ.ʽ.size() - 1) {
                            this.ˎ.ˋ.ॱ(Integer.valueOf(this.ˎ.ʻॱ));
                        }
                        this.ˎ.ॱ.ॱ(Boolean.valueOf(true));
                        return;
                    }
                    this.ˎ.ॱ.ॱ(Boolean.valueOf(false));
                }
            });
            this.ˋॱ.ʽ();
            BaseCardBean ˋ = ˋ(this.ʻॱ);
            if (ˋ != null) {
                int ˎ = dgm.ˎ((Activity) view.getContext());
                this.ᐝ.ˎ(ˋ.ʽᐝ(), ˋ.ॱॱ(), ˎ);
                this.ᐝ.ˋ(ˋ, ˎ);
            }
        }
    }

    private VideoStreamListCardBean ˋ(int i) {
        if (i < 0 || i >= this.ʽ.size()) {
            return null;
        }
        return (VideoStreamListCardBean) this.ʽ.get(i);
    }

    public void ˏ(View view) {
        ॱ(view);
    }

    private void ॱˊ() {
        VideoStreamListCardBean ˋ = ˋ(this.ʻॱ + 1);
        if (ˋ != null) {
            evm.ॱ().ॱ(ˋ.ʻˋ());
        }
    }
}
